class AsyncSeries { // 钩子是同步的
  constructor(args) { // agrs => ['name']
    this.tasks = []
  }
  tapAsync(name, task) {
    this.tasks.push(task)
  }
  callAsync(...args) {
    let finalCalloback = args.pop()
    let index = 0
    let next = () => {
      if (this.tasks.length === index) return finalCalloback()
      let task = this.tasks[index++]
      task(...args, next)
    }
    next()
  }
}

let hook = new AsyncSeries(['name'])
hook.tapAsync('react', function(name, cb) {
    setTimeout(()=> {
      console.log('react', name)
      cb()
    }, 1000)
})
hook.tapAsync('node', function(name, cb) {
    setTimeout(()=> {
      console.log('node', name)
      cb()
    }, 1000)

})
hook.tapAsync('webpack', function(name, cb) {
  setTimeout(()=> {
    console.log('webpack', name)
    cb()
  }, 1000)
})
// hook.call('hl2')
hook.callAsync(['hl1', 'hl2'], ()=> {
  console.log('end')
})

//  AsyncParallelBailHook() 带保险的异步并发的钩子
